<?php
/**
 * Created by PhpStorm.
 * User: lizi
 * Date: 2021/09/03
 * Time: 17:53
 */

namespace App\Console\Commands;

use App\Models\AppMiniPlate;
use App\Models\AppTypeModel;
use App\Models\Config;
use App\Models\Suggest;
use App\Models\SuggestLog;
use App\Models\Order;
use App\Models\MemberOther;
use App\Services\AlipayService;
use App\Services\CommonService;
use App\Services\RadarService;
use Illuminate\Console\Command;

class SuggestTimeCommand extends BaseCommand
{
    /**
     * The name and signature of the console command.
     * @var string
     */
    protected $signature = 'SuggestTime';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '投诉建议超时定时任务';

    /**
     * Create a new command instance.
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     * */
    public function handleExec()
    {

        $listApp=AppTypeModel::query()->select('id','app_name')->get();


        $groupData=['home_active','home_field','great'];

        foreach ($listApp as $item){
            $mini_id=$item['id'];

            $data=Config::where('id',4)->value('value');
            $jump=json_decode($data,true);
            $app_name=AppTypeModel::query()->where('id',$mini_id)->value('app_name');
            if(!empty($mini_id)&&$mini_id==10009){
                $open=0;
                $name=compact('app_name','open','jump');
            }else{
                $name=compact('app_name','jump');
            }
            $jsonContent = json_encode($name, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
            $path =dirname(dirname(dirname(dirname(__FILE__)))) . '/storage/tmp/'.$mini_id.'app_name.json';
            file_put_contents($path,$jsonContent);
            $fileName=$mini_id.'app_name.json';
            AlipayService::upload($fileName,$path);

            foreach ($groupData as $group){

                $data=AppMiniPlate::getAlipayMiniPlate($mini_id,$group);

                $jsonContent = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
                $path = dirname(dirname(dirname(dirname(__FILE__)))) . '/storage/tmp/'.$mini_id.$group.'.json';
                file_put_contents($path,$jsonContent);
                $fileName=$mini_id.$group.'.json';
                AlipayService::upload($fileName,$path);
            }

        }

    }
}
